<!-- $Id: order_info.htm 15544 2009-01-09 01:54:28Z zblikai $ -->

{include file="pageheader.htm"}
{insert_scripts files="topbar.js,../js/utils.js,listtable.js,selectzone.js,jquery.js,../js/common.js"}
  




  <div class="list-div" style="width:500px;margin:auto">
<form name="theForm" action="back.php?act=edit&step=complete" method="post">
    <div id="return_goods">
    <table cellpadding="3" cellspacing="1">
        <tbody>
          <tr>
            <th scope="col" width="180">商品名称</th>
            <th scope="col" width="80">属性</th>
            <th scope="col">退货数量</th>
            <th scope="col">操作</th>
          </tr>
          {foreach from = $return_info.goods_list item = order_goods}
          <tr class="goods">
            <td align="center">{$order_goods.goods_name}</td>
            <td align="center">{$order_goods.goods_attr}</td>
            <td align="center"><input type="text" name="goods_number[{$order_goods.rec_id}]" value="{$order_goods.goods_number}"></td>
            <td><a onclick="delete_goods(this,{$order_goods.rec_id});">删除</a></td>
          </tr>
          {/foreach}
        </tbody>
    </table>  
    </div>
 


    <table cellpadding="3" cellspacing="1" style="margin-top:10px;">
        <tbody>
            <tr>
              <th colspan="2">退货单信息</th>
            </tr>
          <tr>
            <td align="center">添加时间</td>
            <td align="center">{$return_info.add_time} </td>
          </tr>
          <tr>
            <td align="center">快递单号</td>
            <td align="center"><input type="text" name = 'express_sn' value="{$return_info.express_sn}"> </td>
          </tr>
          <tr>
            <td align="center">快递名称</td>
            <td align="center">

            <select name="express_id">
                { foreach from = $express_list item = express_list key = key}
                <option value="{$key}" {if $return_info.express_id eq $key } selected="selected"{/if} >{$express_list}</option>
                {/foreach}
            </select>


            </td>
          </tr>
          <tr>
            <td align="center">退货类型</td>
            <td align="center">
            <select name="service_type">
            { foreach from = $status_list item = status_list key = key}
            <option value="{$key}" {if $return_info.service_type eq $key } selected="selected"{/if} >{$status_list}</option>
            {/foreach}
            </select>
  
            </td>
          </tr>
          <tr>
            <th colspan="2">
              <input type="hidden" name="return_id" value="{$return_info.return_id}">
              <input type="submit" value="提交修改">
            </th>
          </tr>
        </tbody>
    </table> 
</form>
 </div>


<form name="goodsForm" action="" method="post" onsubmit="return addToOrder()">
<p>
  {$lang.search_goods}
  <input type="text" name="keyword" value="" />
  <input type="button" name="search" value="{$lang.button_search}" onclick="searchGoods();" />
  <select name="goodslist" id ="goodslist" onchange="getGoodsInfo(this.value)"></select>
</p>

<div id="order_goods_info">
  <div class="list-div">
    <!--   商品信息 -->
    <table cellpadding="3" cellspacing="1">
      <tr>
        <th width="100">商品名称</th>
        <td id="goods_name">{$goods.goods_name}</td>
      </tr>
      <tr>
        <th>商品编号</th>
        <td id="goods_sku">{$goods.goods_sku}</td>
      </tr>
      <tr class='none'>
        <th>商品分类</th>
        <td id="goods_cat">{$goods.cat_name}</td>
      </tr>
      <tr class='none'>
        <th>商品品牌</th>
        <td id="goods_brand">{$goods.brand_name}</td>
      </tr>

      <!-- 单品属性 -->
      {if $goods.attr_list}
      <tr>
        <th>商品属性<input type="hidden" name="spec_count" value="0" /></th>
        <td id="goods_attr">
           {foreach from=$goods.attr_list item=attr}
           <div style="width:160px; float:left"> <input type="text" name="attr[{$attr.attr_sku}]" style="width:40px;" onchange="stock(this);" >{$attr.attr_value} <span style="color:#b81b1b" class="stock">{$attr.attr_stock}</span></div>
          {/foreach}
        </td>
      </tr>
      {else}
      <tr>
        <th>退货数量</th>
        <td><input name="add_number" type="text" value="1" id="add_number" size="10" {if $from_ad neq 1} onkeyup="up_price(this);" {/if}></td>
      </tr>
      {/if}
      <tr>
        <td colspan="2" align="center"><input name="add_goods" type="submit" value="加入退货单" /></td>
      </tr>
    </table>
    </div>
</div>
</form>



{include file="pagefooter.htm"}

<script>
  
  /**
   * 按商品编号或商品名称或商品货号搜索商品
   */
  function searchGoods()
  {
    var eles = document.forms['goodsForm'].elements;

    /* 填充列表 */
    var keyword = Utils.trim(eles['keyword'].value);
    if (keyword != '')
    {
      Ajax.call('order.php?act=search_goods&keyword=' + keyword, '', searchGoodsResponse, 'GET', 'JSON');
    }
  }

  function searchGoodsResponse(result)
  {
    if (result.message.length > 0)
    {
      alert(result.message);
    }

    if (result.error == 0)
    {
      var eles = document.forms['goodsForm'].elements;

      /* 清除列表 */
      var selLen = eles['goodslist'].options.length;
      for (var i = selLen - 1; i >= 0; i--)
      {
        eles['goodslist'].options[i] = null;
      }

      var arr = result.goodslist;
      var goodsCnt = arr.length;
      if (goodsCnt > 0)
      {
        for (var i = 0; i < goodsCnt; i++)
        {
          var opt = document.createElement('OPTION');
          opt.value = arr[i].goods_id;
          opt.text = arr[i].name;
          eles['goodslist'].options.add(opt);
        }
        getGoodsInfo(arr[0].goods_id);
      }
      else
      {
        getGoodsInfo(0);
      }
    }
  }

  /**
   * 取得某商品信息
   * @param int goodsId 商品id
   */
  function getGoodsInfo(goodsId)
  {

    if (goodsId > 0)
    {
      Ajax.call('back.php?act=get_goods', 'goods_id=' + goodsId, getGoodsInfoResponse, 'get', 'json');
 
    }
    else
    {

    }

  }
  function getGoodsInfoResponse(result)
  {     

        $('#order_goods_info').html('');
        $('#order_goods_info').html(result);
  }
  /**
   * 把商品加入订单
   */
  function addToOrder()
  {
    var eles = document.forms['goodsForm'].elements;

    // 检查是否选择了商品
    if (eles['goodslist'].options.length <= 0)
    {
      alert(pls_search_goods);
      return false;
    }

    var goods_id = $("#goodslist").val();
    var goods_number = $("input:text[name='add_number'] ").val();


    if($("#goods_attr").length>0){
      var attr = {};
      $("#goods_attr").find('div').each(function(){
        var num=$(this).find('input').val();
        var sku = $(this).find('input').attr('sku');
        if(num >0){
         attr[sku]=num;
        }
      });
    }
    var goods_info =
    {
      'goods_id': goods_id,           //商品ID
      'goods_number': goods_number,       //商品数量
    };


    Ajax.call('back.php?act=get_goods_complete&return_id={$return_id}', 'attr='+JSON.stringify(attr)+'&goods_info=' +JSON.stringify(goods_info), addToOrderResponse, 'POST', 'JSON');

    return false;
  }
  function addToOrderResponse(data)
  {
   if(data.error == 0){
      alert(data.content);
   }
   if(data.error == 1){
    $('#return_goods').html("");
    $('#return_goods').html(data.content);
   }
  }
  //删除退货商品
  function delete_goods(obj,rec_id){
    $(obj).parents('.goods').remove();
    Ajax.call('back.php?act=delete_goods', 'rec_id='+rec_id, delete_goods_return, 'POST', 'JSON');


  }
  function delete_goods_return(data){
   
  }



</script>